<?php

namespace Wgx\Admin\Com;

use PhpYes\AppsProxy;
use PhpYes\Com\Render;

abstract class App extends AppProxy
{
    private $packBaseDir;

    private $pageMap;

    /**
     * \Wgx\Admin\Entity\AdminUserEntity
     * \Wgx\Admin\Entity\AdminMenuEntity
     * \Wgx\Admin\Entity\AdminToMenuEntity
     * 这几个 Entity 的数据库连接配置
     * @return \Wgx\Admin\Entity\DbInterface
     */
    abstract public function adminToMenuDb();

    /**
     * \Wgx\Admin\Entity\UserEntity
     * 这个 Entity 的数据库连接配置
     * @return \Wgx\Admin\Entity\DbInterface
     */
    abstract public function userDb();

    /**
     * get this php package base directory
     * @return string
     */
    final public function getPackBaseDir()
    {
        if (empty($this->packBaseDir)) {
            $this->packBaseDir = realpath(__DIR__ . '/..');
        }
        return $this->packBaseDir;
    }

    /**
     * @return array
     */
    final public function getPageMap()
    {
        if (empty($this->pageMap)) {
            $viewDir = self::getPackBaseDir() . '/views';

            $this->pageMap = array(
                Render::PAGE_ERROR => $viewDir . '/error.html.php',
                Render::PAGE_5XX => $viewDir . '/5xx.html.php',
                Render::PAGE_4XX => $viewDir . '/4xx.html.php',
                Render::PAGE_404 => $viewDir . '/404.html.php',

                'admin/admin_menu_listpage.js' => $viewDir . '/admin/admin_menu_listpage.js',
                'admin/admin_to_menu_editpage.js.php' => $viewDir . '/admin/admin_to_menu_editpage.js.php',

                'admin_page_parts/breadcrumb.html.php' => $viewDir . '/admin_page_parts/breadcrumb.html.php',
                'admin_page_parts/css.html.php' => $viewDir . '/admin_page_parts/css.html.php',
                'admin_page_parts/footer.html.php' => $viewDir . '/admin_page_parts/footer.html.php',
                'admin_page_parts/js.html.php' => $viewDir . '/admin_page_parts/js.html.php',
                'admin_page_parts/meta.html.php' => $viewDir . '/admin_page_parts/meta.html.php',
                'admin_page_parts/sidebar.html.php' => $viewDir . '/admin_page_parts/sidebar.html.php',
                'admin_page_parts/topbar.html.php' => $viewDir . '/admin_page_parts/topbar.html.php',
                'admin_page_parts/topbar_inline.css' => $viewDir . '/admin_page_parts/topbar_inline.css',
                'admin_page_parts/topbar_inline.html.php' => $viewDir . '/admin_page_parts/topbar_inline.html.php',

                'adminuser/login.html.php' => $viewDir . '/adminuser/login.html.php',

                'crud/edit.html.php' => $viewDir . '/crud/edit.html.php',
                'crud/list.html.php' => $viewDir . '/crud/list.html.php',
                'crud/read.html.php' => $viewDir . '/crud/read.html.php',
            );
        }
        return $this->pageMap;
    }

}